import { observable, action } from 'mobx'
import { post } from 'lib/net'
import * as api from 'lib/constants/api'
import Toast from 'components/toast'

export default class ArticleVM {
  constructor () {
    this.fetchSwiperData()
    this.fetchListData()
  }
  // 轮播数据
  @observable swiperData = []
  // 列表数据
  @observable listData = []

  // 获取图片轮播
  @action fetchSwiperData = async () => {
    Toast.loading()
    let res = await post(api.ALL_ARTICLE, {})
    if (res.state === 1) {
      this.swiperData = res.data || []
      Toast.loading(2)
    } else {
      console.log(111)
      Toast.fail('获取失败')
    }
  }

  // 获取列表跳转
  @action fetchListData = async () => {
    let params = {
      Offset: 1,
      Limit: 100
    }
    let res = await post(api.ALL_ARTICLE, params)
    if (res.state === 1) {
      this.listData = res.data || []
    }
  }

  // 轮播跳转
  @action handleSwiperItem = item => {
    window.location.href = item.Url
  }

  // 列表跳转
  @action handleListItem = item => {
    window.location.href = item.Url
  }
}
